import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'dva'
import UserList from './List'

function User({location, dispatch, contract, loading}) {

  function onDeleteItem(id) {
    dispatch({
      type: 'contract/delete',
       payload: {id}
     })
  }

  function onEditItem(item) {
    dispatch({
      type: 'contract/showModal',
      payload: {
        type: 'update',
        curItem: item
      }
    })
  }
function onInsertItem(){
  dispatch({
    type: 'contract/insert',
    payload:{}
  })
}

  function onStatusItem(item) {
    dispatch({
      type: 'contract/updateStatus',
      payload: {
        curItem: item
      }
    })
  }

  function onDeleteBatch(id) {
    dispatch({
      type: 'contract/deleteBatch',
      payload: { ids }
    })
  }

  function onSearch(values){
    dispatch({
      type: 'contract/search',
      payload: values
    })
  }

  const listProps = {
    contract,
    loading,
    location,
    onDeleteItem,
    onEditItem,
    onInsertItem,
    onStatusItem,
    onDeleteBatch,
    onSearch,
  }

  return (
    <div className='content-inner'>

      <UserList {...listProps}/>

    </div>
  );
}

User.propTypes = {
  contract: PropTypes.object,
  location: PropTypes.object,
  dispatch: PropTypes.func
};

function mapStateToProps({ contract }){
  return { contract }
}

export default connect(mapStateToProps)(User);
